<?php

/*
 * Niken Larasati
 * larasati.n@students.amikom.ac.id
 */

class kat_pindah extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    function form_kat_pindah() {
        $this->template->load('halaman_v', 'admin/kat_pindah/tambah_kat_pindah_v');
    }

    function tambah() {
        if ($this->input->post('tambah') != NULL)
            ; {
            $data['idkat_pindah'] = $this->input->post('idkat_pindah');
            $data['kat_pindah'] = $this->input->post('kat_pindah');

            $this->load->model('umum_m');
            $this->umum_m->tambah('kat_pindah', $data);
            $this->tampil();
        }
    }

    function ubah($id = NULL) {
        if ($id != NULL) {
            $this->load->model('umum_m');
            $data['data_kat_pindah'] = $this->umum_m->ambil_data('kat_pindah', 'idkat_pindah = ' . $id)->row();
            $this->template->load('halaman_v', 'admin/kat_pindah/ubah_kat_pindah_v', $data);
        } else {
            redirect('admin/kat_pindah');
        }
    }

    function simpan_ubah() { //kalau data tidak diubah,maka....?
        if ($this->input->post() != null) {
            $kat_pindah['idkat_pindah'] = $this->input->post('idkat_pindah');
            $kat_pindah['kat_pindah'] = $this->input->post('kat_pindah');

            $this->load->model('umum_m');
            if ($this->umum_m->ubah('kat_pindah', $kat_pindah, 'idkat_pindah', $kat_pindah['idkat_pindah'])) {
                redirect('admin/kat_pindah/tampil');
            }
        }
    }
    

    function tampil() {
        $this->load->model('kat_pindah_m');
        $data['kat_pindah'] = $this->kat_pindah_m->ambil_data();
        $this->template->load('halaman_v', 'admin/kat_pindah/tampil_kat_pindah_v', $data);
    }
    
    function hapus($id = NULL){
        if($id != NULL){
            $this->load->model('umum_m');
            $status = $this->umum_m->cek_relasi_tabel('pindah_pergi','idkat_pindah',$id);
            $status = $this->umum_m->cek_relasi_tabel('pindah_datang','idkat_pindah',$id);
            if($status == 0){
                $this->umum_m->hapus_data_tabel('kat_pindah',  array('idkat_pindah'=>$id));
                $this->tampil();
            }
        }        
    }

}
?>